﻿package mortal.game.resource.tableConfig
{
    import Message.DB.Tables.*;
    import __AS3__.vec.*;
    import com.gengine.resource.*;
    import flash.utils.*;
    import mortal.game.view.common.*;

    public class ChallengeCopyConfig extends Object
    {
        private var _challengCopyDic:Dictionary;
        private var _challengeList:Vector.<TChallengeCopy>;
        private static var _instance:ChallengeCopyConfig;

        public function ChallengeCopyConfig()
        {
            this._challengCopyDic = new Dictionary();
            this._challengeList = new Vector.<TChallengeCopy>;
            if (_instance != null)
            {
                throw new Error(" ChallengeCopyConfig 单例 ");
            }
            this.init();
            return;
        }// end function

        private function init() : void
        {
            var _loc_1:* = ConfigManager.instance.getJSONByFileName("t_challenge_copy.json");
            this.write(_loc_1);
            return;
        }// end function

        private function write(param1:Object) : void
        {
            var _loc_2:TChallengeCopy = null;
            var _loc_3:Object = null;
            for each (_loc_3 in param1)
            {
                
                _loc_2 = new TChallengeCopy();
                ClassTypesUtil.copyValue(_loc_2, _loc_3);
                if (this._challengCopyDic[_loc_2.tower] == null)
                {
                    this._challengCopyDic[_loc_2.tower] = new Dictionary();
                }
                if (this._challengCopyDic[_loc_2.tower][_loc_2.section] == null)
                {
                    this._challengCopyDic[_loc_2.tower][_loc_2.section] = new Dictionary();
                }
                this._challengCopyDic[_loc_2.tower][_loc_2.section][_loc_2.level] = _loc_2;
                this._challengeList.push(_loc_2);
            }
            return;
        }// end function

        public function get challengeCopyList() : Vector.<TChallengeCopy>
        {
            return this._challengeList;
        }// end function

        public function get challengCopyDic() : Dictionary
        {
            return this._challengCopyDic;
        }// end function

        public function getMaxLevelByTowerAndSection(param1:int, param2:int) : int
        {
            var _loc_3:int = 0;
            var _loc_5:TChallengeCopy = null;
            var _loc_4:* = this._challengCopyDic[param1][param2];
            for each (_loc_5 in _loc_4)
            {
                
                _loc_3++;
            }
            return _loc_3;
        }// end function

        public function getDataByTowerAndSectionAndDif(param1:int, param2:int, param3:int) : TChallengeCopy
        {
            var _loc_4:TChallengeCopy = null;
            if (this._challengCopyDic[param1])
            {
                if (this._challengCopyDic[param1][param2])
                {
                    _loc_4 = this._challengCopyDic[param1][param2][param3];
                }
            }
            return _loc_4;
        }// end function

        public function getMagicTowerByTowerAndLevel(param1:int, param2:int) : TChallengeCopy
        {
            var _loc_3:TChallengeCopy = null;
            if (this._challengCopyDic[param1])
            {
                if (this._challengCopyDic[param1][5])
                {
                    _loc_3 = this._challengCopyDic[param1][5][param2];
                }
            }
            return _loc_3;
        }// end function

        public function getTchallengeByMedalCode(param1:int) : TChallengeCopy
        {
            var _loc_2:TChallengeCopy = null;
            var _loc_3:TChallengeCopy = null;
            for each (_loc_3 in this._challengeList)
            {
                
                if (_loc_3.medalId == param1)
                {
                    _loc_2 = _loc_3;
                    break;
                }
            }
            return _loc_2;
        }// end function

        public static function get instance() : ChallengeCopyConfig
        {
            if (_instance == null)
            {
                _instance = new ChallengeCopyConfig;
            }
            return _instance;
        }// end function

    }
}
